package indi.yangshenhui.spring.controller;

import java.util.List;

import indi.yangshenhui.hbase.dao.HBaseHelper;
import indi.yangshenhui.hbase.dao.constant.HBaseConstant;
import indi.yangshenhui.hbase.dao.entity.htable.HBaseTableDescribesEntity;
import indi.yangshenhui.hbase.dao.pool.HTablePoolEngine;
import indi.yangshenhui.spring.constant.PropertiesConstant;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;

@Controller
public class ListHBaseTableController {
	private static final Logger LOGGER = Logger
			.getLogger(ListHBaseTableController.class);

	@RequestMapping("listtable.do")
	public String listTable(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			HTablePoolEngine.createHBaseConfiguration(
					HBaseConstant.HBASE_DEFAULT_INSTANCE,
					PropertiesConstant.HBASE_PROPERTIES
							.getProperty("hbase.zookeeper.quorum"),
					PropertiesConstant.HBASE_PROPERTIES.getProperty(""
							+ "hbase.zookeeper.property.clientport"));
			List<HBaseTableDescribesEntity> hBaseTableDescribesEntityList = HBaseHelper
					.list(HBaseConstant.HBASE_DEFAULT_INSTANCE);
			response.getWriter().write(
					JSON.toJSONString(hBaseTableDescribesEntityList));
		} catch (Exception e) {
			LOGGER.error(e.getMessage(), e);
		}
		return null;
	}

}